package leetcode.weekly.week319;

//Solution2Test
public class Solution2 {

	public int subarrayLCM(int[] nums, int k) {
		int ans = 0;
		for (int i = 0; i < nums.length; i++) {
			int n1 = nums[i];
			for (int j = i; j >= 0; j--) {
				int n2 = nums[j];
				int lcm = this.lcm(n1, n2);
				if (lcm == k) {
					ans++;
				}
				n1 = lcm;
			}
		}
		return ans;
	}


	public int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

}
